package com.zhangjingcheng.yunyixia.controller;

import com.zhangjingcheng.yunyixia.pojo.dto.LoadFileListDTO;
import com.zhangjingcheng.yunyixia.pojo.vo.FileVO;
import com.zhangjingcheng.yunyixia.result.PageResult;
import com.zhangjingcheng.yunyixia.result.Result;
import com.zhangjingcheng.yunyixia.service.FileService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/recycle")
public class RecycleController {
    @Autowired
    private FileService fileService;

    /**
     * 回收站列表
     *
     * @param dto
     * @return
     */
    @ApiOperation("回收站列表")
    @GetMapping("/list")
    public PageResult<FileVO> list(LoadFileListDTO dto) {
        log.info("开始加载文件列表：{}", dto);
        return fileService.list(dto);
    }

    /**
     * 恢复文件
     *
     * @param ids
     * @return
     */
    @ApiOperation("恢复文件")
    @PostMapping("/restore")
    public Result<String> restore(@RequestBody List<Integer> ids) {
        log.info("开始恢复文件：{}", ids);
        fileService.updateFlag(ids);
        return Result.success();
    }

    /**
     * 彻底删除文件
     *
     * @param ids
     * @return
     */
    @ApiOperation("彻底删除文件")
    @DeleteMapping("/delFile")
    public Result<String> delFile(@RequestBody List<Integer> ids) {
        log.info("开始彻底删除文件：{}", ids);
        fileService.deleteByIds(ids);
        return Result.success();
    }

}
